<?php

/**
 * This file is part of the Framework03 PHP framework.
 * @author Walter Tamboer
 * @package Framework03
 */
 
class FW_Controller_Router_PregRegex extends FW_Controller_Router_Abstract
{
    private $regex;
    
    private $options;

    public function __construct($regex, array $options)
    {
        $this->regex = $regex;
        $this->options = $options;
    }
    
    public function route(FW_Controller_Request_Abstract $request)
    {
        $pathInfo = $request->getPathInfo();
        
        if (!preg_match($this->regex, $pathInfo, $matches))
            return false;

        $request->setControllerName($this->options['controller']);
        $request->setActionName($this->options['action']);
        
        array_shift($matches);
        $request->setArguments($matches);

        return true;
    }
}
